package com.zh.goods.service.impl;


import com.zh.common.utils.R;
import com.zh.common.utils.ShiroUtils;
import com.zh.common.utils.StringUtil;
import com.zh.goods.dao.GoodsSublistDao;
import com.zh.goods.domain.GoodsSublistDO;
import com.zh.goods.service.GoodsSublistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;


@Service
public class GoodsSublistServiceImpl implements GoodsSublistService {
	@Autowired
	private GoodsSublistDao scGoodsSublistDao;
	
	@Override
	public GoodsSublistDO get(String id){
		return scGoodsSublistDao.get(id);
	}
	
	@Override
	public List<GoodsSublistDO> list(Map<String, Object> map){
		return scGoodsSublistDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return scGoodsSublistDao.count(map);
	}
	
	@Override
	public int save(GoodsSublistDO scGoodsSublist){
		scGoodsSublist.setId(StringUtil.generalKeyword());
		scGoodsSublist.setCreateBy(ShiroUtils.getUserId());
		scGoodsSublist.setServiceId(ShiroUtils.getUserId());
		scGoodsSublist.setCreateDate(new Date());
		scGoodsSublist.setFlag(0);
		return scGoodsSublistDao.save(scGoodsSublist);
	}
	
	@Override
	public int update(GoodsSublistDO scGoodsSublist){
		return scGoodsSublistDao.update(scGoodsSublist);
	}
	
	@Override
	public int remove(String id){
		return scGoodsSublistDao.remove(id);
	}
	
	@Override
	public int batchRemove(String[] ids){
		return scGoodsSublistDao.batchRemove(ids);
	}

	@Override
	public int removeByGoodsId(String id){return scGoodsSublistDao.removeByGoodsId(id);}

	@Override
	public int batchRemoveByGoodsId(String[] ids){return scGoodsSublistDao.batchRemoveByGoodsId(ids);}

	@Override
	public List<GoodsSublistDO> listAll(String id){

		return scGoodsSublistDao.listAll(id);
	}

	/**
	 * @param id
	 * @return 商品子表中商品上架
	 */
	@Override
	public R putaway(String id) {

		GoodsSublistDO advertisementDO = scGoodsSublistDao.get(id);
		advertisementDO.setFlag(1);
		advertisementDO.setUpdateDate(new Date());
		scGoodsSublistDao.update(advertisementDO);
		return R.ok();

	}


	/**
	 * @param id
	 * @return 商品子表中商品下架
	 */
	@Override
	public R soldOut(String id) {

		GoodsSublistDO advertisementDO = scGoodsSublistDao.get(id);
		advertisementDO.setFlag(0);
		advertisementDO.setUpdateDate(new Date());
		scGoodsSublistDao.update(advertisementDO);
		return R.ok();

	}
	@Override
	public int countAdd(String id){

		return scGoodsSublistDao.countAdd(id);
	}
	@Override
	public int getStock(String goodsId){

		return  scGoodsSublistDao.getStock(goodsId);
	}

    @Override
	public  List<GoodsSublistDO> getColour(String goodsId){

		return  scGoodsSublistDao.getColour(goodsId);

	}

	@Override
	public  List<GoodsSublistDO> getSpecification(String goodsId){
		return  scGoodsSublistDao.getSpecification(goodsId);
	}

    @Override
	public  List<GoodsSublistDO> getDataByGoodsId(String goodsId ){

		return  scGoodsSublistDao.getDataByGoodsId(goodsId);
	}



}
